import multiprocessing
import subprocess
import sys

def run_job(job_file):
    try:
        result = subprocess.run([sys.executable, job_file], capture_output=True, text=True)
        print(f"Running {job_file}:\n{result.stdout}")
        if result.stderr:
            print(f"Errors in {job_file}:\n{result.stderr}")
    except Exception as e:
        print(f"Failed to run {job_file}: {str(e)}")

if __name__ == '__main__':
    job_files = ['1-DownloadAllAkshare.py', '2-MergeBasicData.py', '3-BasicIndicators.py','4-TradeProcessor.py']
    processes = []

    for job in job_files:
        process = multiprocessing.Process(target=run_job, args=(job,))
        processes.append(process)
        process.start()

    for process in processes:
        process.join()

    print("All jobs completed.")